/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.adaptor;

import org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext;
import org.springframework.osgi.extender.internal.dependencies.startup.ContextExecutorStateAccessor;
import org.springframework.osgi.extender.internal.dependencies.startup.ContextState;
import org.springframework.osgi.extender.internal.dependencies.startup.DependencyServiceManager;

import com.cqcis.uip.base.framework.core.impl.ServiceStateManage;

/**
 * @author huangmy
 * @date   2008-3-24
 */
public class DependencyServiceManagerAdaptor extends DependencyServiceManager {
	private ServiceStateManage ssm;
	private DelegatedExecutionOsgiBundleApplicationContext context;
	
	public DependencyServiceManagerAdaptor(ContextExecutorStateAccessor executor,
			DelegatedExecutionOsgiBundleApplicationContext context, Runnable executeIfDone, ServiceStateManage ssm) {
		super(executor, context, executeIfDone);
		this.ssm = ssm;		
		this.context = context;
	}

	@Override
	protected void findServiceDependencies() {
		try {
			super.findServiceDependencies();
    	} catch (Throwable t) {
    		// 分析XML抛出异常, 包括类无法找到异常
    		ssm.updateState(context.getBundle().getBundleId(), ContextState.INTERRUPTED, "DependencyServiceManager findServiceDependencies Exception.", t); 
    		
    		throw new RuntimeException(t);
    	}
	}
}
